package com.neouton.crm.approval.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.neouton.common.entity.ActivitiVO;
import com.neouton.common.util.AuthUtils;
import com.neouton.common.util.PageUtil;
import com.neouton.common.util.ResponseAPI;
import com.neouton.crm.approval.entity.ApprovalLogVO;
import com.neouton.crm.approval.entity.ApprovalVO;
import com.neouton.crm.entity.SysUserEntity;

import java.util.List;
import java.util.Map;

public interface IApprovalService {

    /**
     * 分页查询待办审批
     * @param page
     * @param approval
     * @return
     */
    PageUtil<ApprovalVO> queryApprovalByPage(IPage<ApprovalVO> page, ApprovalVO approval);
    List<ApprovalVO> queryApprovalByPage(ApprovalVO approval);

    /**
     * 更具ID查询审批主表
     * @param approvalId
     * @return
     */
    ApprovalVO queryApprovalByAppID(Integer approvalId);

    /**
     * 查询审批日志
     * @param approvalId
     * @return
     */
    List<ApprovalLogVO> queryApprovalLogByAppID(Integer approvalId);

    /**
     * 发我审批，生成审批主表信息
     * @param approval 主表信息
     * @return
     */
    Boolean initiateApproval(ApprovalVO approval);

    /**
     * 审批通过 多字段判断，可根据工作流ID，进行操作
     * @param businessId 工作流ID
     * @param approvalId 审批表主键
     * @return
     */
    Boolean approved(Integer businessId,Integer approvalId);


    /**
     * 审批驳回 多字段判断，可根据工作流ID，审批表主键进行操作
     * @param businessId 工作流ID
     * @param approvalId 与待办通知数据保持一致，统一为auth数据字典配置字段
     * @return
     */
    Boolean approvalRejection(Integer businessId,Integer approvalId);

    /**
     *
     * @param approvalId 审批主表ID
     * @param operationType 操作类型
     * @param operationDesc 操作描述
     * @param opinion 审批意见
     * @return
     */
    Boolean insertApprovalLog(Integer approvalId,String operationType,String operationDesc,String opinion);

    /**
     * 生成审批主表，同时生成日志表
     * @param businessId 工作流ID
     * @param approvalType 审批类型，与auth数据字典配置一致
     * @param askReason 申请原因
     * @param operationDesc 操作描述
     * @param nextApprover 下一处理人
     * @param remark 备注
     * @return 审批主表主键
     */
    ApprovalVO initApprovalAndLog(Integer businessId,Integer approvalType,String askReason,
                               String operationDesc,Integer nextApprover, String remark);

    /**
     * 查询审批记录，更具审批类型
     * @param page 分页
     * @param approval 审批实体类
     * @return
     */
    PageUtil<ApprovalVO> queryApprovalRecordByType(IPage<ApprovalVO> page,ApprovalVO approval,String token);
    List<ApprovalVO> queryApprovalRecordByType(ApprovalVO approval,String token);


    /**
     * 已办审批查询
     * @param pageNum
     * @param pageSize
     * @param approval
     * @return
     */
    PageUtil<ApprovalVO> queryApprovalDoneRecordByType(Integer pageNum, Integer  pageSize,ApprovalVO approval);
    List<ApprovalVO> queryApprovalDoneRecordByType(ApprovalVO approval);


    /**
     * 更新下一处理人
     * @param userId 下一处理人ID
     * @param approvalId 审批ID
     * @return
     */
    Boolean updateNextApproverByApprovalId(Integer userId,Integer approvalId);

    /**
     * 撤回工作流
     * @param approval 审批实例
     * @return
     */
    Boolean deleteInstance(ApprovalVO approval,String token);

    /**
     * 获取审批日志
     * @param approvalId
     * @return
     */
    List<Map<String,String>> queryApprovalLog(Integer approvalId);


    /**
     * 通过多个审批ID获取审批日志集合
     * @param approvalIdList
     * @return
     */
    List<Map<String,String>> queryApprovalLogList(List<Integer> approvalIdList);


    /**
     * 提交撤回申请
     * @param approval
     * @return
     */
    Boolean saveWithdraw(ApprovalVO approval,String token);

    /**
     * 审批通过
     * @param approval
     * @return
     */
    Boolean approveWithdraw(ApprovalVO approval,String token);

    /**
     * 审批驳回
     * @param approval
     * @return
     */
    Boolean rejectionWithdraw(ApprovalVO approval, String token);


    /**
     * 分页查询待办任务
     * @param page
     * @param approval
     * @return
     */
    PageUtil<ApprovalVO> queryWithdrawalApprovalByPage(IPage<ApprovalVO> page, ApprovalVO approval);

    /**
     * 已办审批查询
     * @param pageNum
     * @param pageSize
     * @param approval
     * @return
     */
    PageUtil<ApprovalVO> queryWithdrawalApprovalDoneRecordByType(Integer pageNum, Integer  pageSize, ApprovalVO approval);

    /**
     * 查询审批记录，更具审批类型
     * @param page 分页
     * @param approval 审批实体类
     * @return
     */
   PageUtil<ApprovalVO> queryWithdrawalApprovalRecordByType(IPage<ApprovalVO> page, ApprovalVO approval, String token);

   List<String> queryApprovalStepsByApprovalCode(String approvalCode);
}
